#pragma once
#include "Shirt.h"
#include "Doll.h"
Shirt *shirt1;
Doll doll;
void display(void)
{
	
	//ball_time++;
	//ball_pos.f[2] = cos(ball_time/50.0)*7;

	shirt1->addForce(Vec3(0,-0.2,0)*TIME_STEPSIZE2); // add gravity each frame, pointing down
	shirt1->windForce(Vec3(0.5,0,0.2)*TIME_STEPSIZE2); // generate some wind each frame
	shirt1->timeStep(); // calculate the particle positions of the next frame
	shirt1->ballCollision(ball_pos,ball_radius); // resolve collision with the ball



	// drawing

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	glDisable(GL_LIGHTING); // drawing some smooth shaded background - because I like it ;)
	glBegin(GL_POLYGON);
	glColor3f(0.8f,0.8f,1.0f);
	glVertex3f(-200.0f,-100.0f,-100.0f);
	glVertex3f(200.0f,-100.0f,-100.0f);
	glColor3f(0.4f,0.4f,0.8f);	
	glVertex3f(200.0f,100.0f,-100.0f);
	glVertex3f(-200.0f,100.0f,-100.0f);
	glEnd();
	glEnable(GL_LIGHTING);

	glTranslatef(-6.5,6,-9.0f); // move camera out and center on the cloth
	glRotatef(25,0,1,0); // rotate a bit to see the cloth from the side
	shirt1->drawShaded(); // finally draw the cloth with smooth shading
	
	//glPushMatrix(); // to draw the ball we use glutSolidSphere, and need to draw the sphere at the position of the ball
	//glTranslatef(ball_pos.f[0],ball_pos.f[1],ball_pos.f[2]); // hence the translation of the sphere onto the ball position
	//glColor3f(0.4f,0.8f,0.5f);
	//glutSolidSphere(ball_radius-0.1,50,50); // draw the ball, but with a slightly lower radius, otherwise we could get ugly visual artifacts of cloth penetrating the ball slightly
	//glPopMatrix();

	doll.drawShaded();

	glutSwapBuffers();
	glutPostRedisplay();
}
int main ( int argc, char** argv ) 
{
	shirt1 = new Shirt("a.txt","a.txt");
	//mesh1.LoadData("a.txt");
	//mesh1.SaveData("b.txt");
	glutInit( &argc, argv );

	
	glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); 
	glutInitWindowSize(640, 480 ); 

	glutCreateWindow( "Cloth Tutorial from cg.alexandra.dk" );
	init();
	glutDisplayFunc(display);  
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
	glutSpecialFunc(arrow_keys);

	glutMainLoop();
}